package wyh.filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//拦截所有的请求改成中文UTF-8编码
@WebFilter("/*")
//                        实现 Filter
public class ZhongWen implements Filter {
    //            重写doFilter
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//                    set返回Char字符En设置UTF-8
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setCharacterEncoding("UTF-8");
//        最后一个形参重写一遍doFilter
//        doFilter核心作用是将请求和响应沿着过滤器链继续传递下去
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
